var common = require('../controller/commonController.js');

var InhouseModel = require("../model/InhouseModel.js");
var setting = require("../database/setting.js");
var Mysql = require("node-mysql-promise");

class InhouseController{
	constructor() {
		this.inhouseModel = new InhouseModel();
		this.connection = Mysql.createConnection(setting);
	}

	//从数据哭中获取所有数据
	getInhouseOrderAll(callback){
		var sqlStr = "";
		sqlStr = 'SELECT * from tb_inhouse order by inhouse_date,tenant_name';
		this.inhouseModel.findAllOrderByDate(this.connection,sqlStr).then((data) => {
			data.forEach((value)=>{
		   	   value.inhouse_date = common.timeChange(value.inhouse_date);//处理日期类型
		   	   value.currently_num = value.commodity_num;//当前量等于库存量
		    });
		    callback(data);
		});
	}

	saveDealData(data,callback){
		this.inhouseModel.addNewInTable(this.connection,data).then(function(value){
			callback('success');
		});
	}

}

module.exports = InhouseController;